package com.bjsxt.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.CoinRecharge;
import com.bjsxt.model.Result;
import com.bjsxt.modle.CoinRechargeVo;
import com.bjsxt.service.CoinRechargeService;
import com.bjsxt.util.SpringSecurityUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;

/**
 * description:
 * 充币记录控制层
 * TODO: 这里在进行权限配置的时候可能没有对应的权限，以后后期需要统一进行添加
 *
 * @author ALIENWARE
 * @version v1.0.0
 * @create 4/27/2024
 **/
@RestController
@RequestMapping("/coinRecharge")
@Api(tags = "充币记录控制器")
public class CoinRechargeController {

    /**
     * 充币记录业务层对象
     */
    @Autowired
    private CoinRechargeService coinRechargeService;

    /**
     * 条件分页查询充币记录
     *
     * @param page      分页对象<CoinRecharge>
     * @param coinId    币种 ID
     * @param userId    用户 ID
     * @param userName  用户名
     * @param mobile    手机号码
     * @param status    状态
     * @param numMin    最小充值金额
     * @param numMax    最大充值金额
     * @param startTime 开始日期
     * @param endTime   结束日期
     * @return 统一响应对象
     */
    @GetMapping("/records")
    // @PreAuthorize("hasAuthority('trade_coin_type_query')")
    @ApiOperation(value = "条件分页查询充币记录", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "coinId", value = "币种 ID", dataType = "Long", paramType = "query", example = "0991"),
            @ApiImplicitParam(name = "userId", value = "用户 ID", dataType = "Long", paramType = "query", example = "9001"),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query", example = "张三"),
            @ApiImplicitParam(name = "mobile", value = "手机号码", dataType = "String", paramType = "query", example = "13517765487"),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Byte", paramType = "query", example = "0"),
            @ApiImplicitParam(name = "numMin", value = "最小充值金额", dataType = "Integer", paramType = "query", example = "0"),
            @ApiImplicitParam(name = "numMax", value = "最大充值金额", dataType = "Long", paramType = "query", example = "100"),
            @ApiImplicitParam(name = "startTime", value = "开始日期", dataType = "Long", paramType = "query", example = "1970-01-01"),
            @ApiImplicitParam(name = "endTime", value = "结束日期", dataType = "Long", paramType = "query", example = "1970-01-02")
    })
    public Result<Page<CoinRechargeVo>> findByPage(@ApiIgnore Page<CoinRecharge> page, Long coinId, Long userId, String userName, String mobile, Byte status, Integer numMin, Integer numMax, @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime) {
        page.addOrder(OrderItem.desc(CoinRecharge.COL_LAST_UPDATE_TIME));
        // 调用业务层进行分页数据的查询
        Page<CoinRechargeVo> coinRechargePage = coinRechargeService.pageByCoinIdAndUserIdAndUserNameAndMobileAndStatusAndNumAndCreateTime(page, coinId, userId, userName, mobile, status, numMin, numMax, startTime, endTime);
        // 返回响应数据
        return Result.success(coinRechargePage);
    }

    /**
     * 条件分页查询充币记录
     *
     * @param page   分页对象<CoinRecharge>
     * @param coinId 币种 ID
     * @return 统一响应对象
     */
    @GetMapping("/user/records")
    // @PreAuthorize("hasAuthority('trade_coin_type_query')")
    @ApiOperation(value = "条件分页查询充币记录", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "coinId", value = "币种 ID", dataType = "Long", paramType = "query", example = "0991")
    })
    public Result<Page<CoinRecharge>> findByPage(@ApiIgnore Page<CoinRecharge> page, Long coinId) {
        page.addOrder(OrderItem.desc(CoinRecharge.COL_LAST_UPDATE_TIME));
        // 获取当前用户
        Long userId = SpringSecurityUtils.getCurrentUserId();
        // 调用业务层进行分页数据的查询
        Page<CoinRecharge> coinRechargePage = coinRechargeService.pageByUserIdAndCoinId(page, userId, coinId);
        // 返回响应数据
        return Result.success(coinRechargePage);
    }
}
